package 滑动;

public class _643子数组最大平均数1 {
    /**
     * nums = [1,12,-5,-6,50,3], k = 4
     */
    public static double findMaxAverage(int[] nums, int k) {
        int r=Integer.MIN_VALUE;
        int sum=0;
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            sum+=nums[i];
            if(i<k-1){
                continue;
            }
            r=Math.max(r, sum);
            sum-=nums[i-k+1];
        }
        return ((double)r)/k;
    }

    public static void main(String[] args) {
        System.out.println("main:"+findMaxAverage(new int[]{1,12,-5,-6,50,3}, 4));
        System.out.println("main:"+findMaxAverage(new int[]{5}, 1));
        
    }

}
